package sk.tuke.android4all.messenger;

import java.util.ArrayList;
import java.util.List;

public class CollectionHelper<T> {

	private List<T> mCollection;
	private int mItemsPerPage = 1;
	private int startIndex = 0;
	
	public CollectionHelper(List<T> aCollection_in, int aItemsPerPage_in){
		mCollection = aCollection_in;
		mItemsPerPage = aItemsPerPage_in;
	}
	
	public List<T> getNext(){
		if(mCollection.size() <= mItemsPerPage){
			return mCollection;
		}
		int index = startIndex;
		
		List<T> newCollection = new ArrayList<T>();
		for(int i = 0; i< mItemsPerPage; i++){
			T item = null;
			if(index + i > mItemsPerPage){
				index = -i;
			}
			item = mCollection.get(startIndex + i);
			newCollection.add(item);
		}
		startIndex = mItemsPerPage + index;
		
		return newCollection;
	}
}
